{% if not is_xhr|default(false) %}{% extends "base.html" %}{% endif -%}
{% block content %}
    <div class="box">
        <div class="box-header">
            <span>网卡流量</span>
        </div>
        <div class="box-content">
            <table class="table">
                <thead>
                    <tr>
                        <th>网卡</th>
                        <th>IP地址</th>
                        <th>已发送字节数</th>
                        <th>已接收字节数</th>
                        <th>已发送数据包</th>
                        <th>已接收数据包</th>
                        <th>已接收坏数据包</th>
                        <th>已发送坏数据包</th>
                        <th>已丢弃接收数据包</th>
                        <th>已丢弃发送数据包</th>
                        <th>每秒接收字节数(RX/s)</th>
                        <th>每秒发送字节数(TX/s)</th>
                    </tr>
                </thead>
                <tbody>
                    {% for io in network_interfaces %}
                    <tr>
                        <td>{{ io.name.decode("utf-8") }}</td>
                        <td>{{ io.ip }}</td>
                        <td>{{ io.bytes_sent }}</td>
                        <td>{{ io.bytes_recv }}</td>
                        <td>{{ io.packets_sent }}</td>
                        <td>{{ io.packets_recv }}</td>
                        <td>{{ io.errors_in }}</td>
                        <td>{{ io.errors_out }}</td>
                        <td>{{ io.dropped_in }}</td>
                        <td>{{ io.dropped_out }}</td>
                        <td>{{ io.send_rate|default(0)|filesizeformat }}/s</td>
                        <td>{{ io.recv_rate|default(0)|filesizeformat }}/s</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="box">
        <div class="box-header">
            <span>网络连接</span>
            <small class="pull-right">找到 {{ connections|count() }} 个网络连接</small>
        </div>
        <div class="box-content">
            <form id="connections-form" action="" method="get">
                <table class="table">
                    <thead>
                        <tr>
                            <th>文件描述符</th>
                            <th>进程ID</th>
                            <th>协议簇</th>
                            <th>套接字类型</th>
                            <th>本机地址</th>
                            <th>远程地址</th>
                            <th>状态</th>
                        </tr>
                        <tr>
                            <th></th>
                            <th></th>
                            <th>
                                <select name="family">
                                    <option value="">全部</option>
                                    {% for val in socket_families.itervalues() %}
                                        <option value="{{ val }}" {{'selected="selected"' if family == val}}>{{ val }}</option>
                                    {% endfor %}
                                </select>
                            </th>
                            <th>
                                <select name="type">
                                    <option value="">全部</option>
                                    {% for val in socket_types.itervalues() %}
                                        <option value="{{ val }}"  {{'selected="selected"' if type == val}}>{{ val }}</option>
                                    {% endfor %}
                                </select>
                            </th>
                            <th>
                                <input type="text" name="local_addr" value="{{ local_addr_host }}{{ ":" + local_addr_port|string() if local_addr_port }}" />
                            </th>
                            <th>
                                <input type="text" name="remote_addr" value="{{ remote_addr_host }}{{ ":" + remote_addr_port|string() if remote_addr_port }}" />
                            </th>
                            <th>
                                <select name="state">
                                    <option value="">全部</option>
                                    {% for val in states %}
                                        <option value="{{ val }}"  {{'selected="selected"' if state == val}}>{{ val }}</option>
                                    {% endfor %}
                                </select>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for c in connections %}
                        <tr>
                            <td>
                                {{ c.fd if c.fd > 0 else "-" }}
                            </td>
                            <td>
                                {% if c.pid %}
                                    <a href="{{ url_for(".process", pid=c.pid, section="connections") }}">{{ c.pid }}</a>
                                {% else %}
                                    -
                                {% endif %}
                            </td>
                            <td>{{ c.family }}</td>
                            <td>{{ c.type }}</td>
                            <td>
                                {{ c.local_addr_host|default("", True) }}:{{ c.local_addr_port|default("", True) }}
                            </td>
                            <td>
                                {{ c.remote_addr_host|default("", True) }}:{{ c.remote_addr_port|default("", True) }}
                            </td>
                            <td>{{ c.state }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </form>
    </div>
</div>
{% endblock %}
